package com.lovo.homework0201.controller;

import com.lovo.homework0201.dao.IUserPowerDao;
import com.lovo.homework0201.entity.UserEntity;
import com.lovo.homework0201.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("user")
@Api(tags = "用户控制层")
public class UserController {
    @Autowired
    IUserService userService;
    @Autowired
    IUserPowerDao userPowerDao;

    @ApiOperation(value = "登录")
    @PostMapping("login")
    public boolean login(@RequestBody UserEntity user, HttpServletRequest request){
        Subject subject =  SecurityUtils.getSubject();
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(user.getUserName(),user.getPassWord());
        try {
            subject.login(usernamePasswordToken);
            return true;
        }catch (Exception e){
            return false;
        }
    }
    @ApiOperation(value = "权限1")
    @DeleteMapping("rmv")
    public String power1(){
        return "ok";
    }
    @ApiOperation(value = "权限2")
    @PutMapping("ruku")
    public String power2(){
        return "ok";
    }
    @ApiOperation(value = "权限3")
    @GetMapping("power3")
    public String power3(){
        return "ok";
    }
}
